package kr.hkit.androidcomplete01.ch07;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader.TileMode;
import android.os.Bundle;
import android.view.View;

public class LinearGrad extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyView vw = new MyView(this);
		setContentView(vw);
	}
	
	class MyView extends View{

		public MyView(Context context) {
			super(context);
		}
		
		
		public void onDraw(Canvas canvas){
			Paint pnt = new Paint();
			pnt.setAntiAlias(true);
			
			int[] colors = {Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.WHITE};
			float[] pos = {0.0f, 0.1f, 0.6f, 0.9f, 1.0f};
			
			//수평
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 0, 100, 100, pnt);
			//우하향
			pnt.setShader(new LinearGradient(110, 0, 210, 100, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(110, 0, 210, 100, pnt);
			//우상향
			pnt.setShader(new LinearGradient(220, 100, 320, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(220, 0, 320, 100, pnt);
			//가장자리 반복
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.CLAMP));
			canvas.drawRect(0, 110, 320, 150, pnt);		
			//무늬 반복
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.REPEAT));
			canvas.drawRect(0, 160, 320, 200, pnt);	
			//무늬 반사 반복
			pnt.setShader(new LinearGradient(0, 0, 100, 0, Color.BLUE, Color.WHITE, TileMode.MIRROR));
			canvas.drawRect(0, 210, 320, 250, pnt);
			//여러 가지 색상 균등 배치
			pnt.setShader(new LinearGradient(0, 0, 320, 0, colors, null, TileMode.CLAMP));
			canvas.drawRect(0, 260, 320, 300, pnt);
			//여러 가지 색상 임의 배치
			pnt.setShader(new LinearGradient(0, 0, 320, 0, colors, pos, TileMode.CLAMP));
			canvas.drawRect(0, 310, 320, 350, pnt);			
		}
	}
}
